package Question3_1;
public class Question {
	static int stacksize = 10;
	static int [] array = new int[stacksize*3];
	static int [] stackpointer = {-1,-1,-1};
	public static void main(String[] args) throws Exception{
		push(2, 4); 
        System.out.println("Peek 2: " + peek(2)); 
        push(0, 3); 
        push(0, 7); 
        push(0, 5); 
        System.out.println("Peek 0: " + peek(0)); 
        pop(0); 
        System.out.println("Peek 0: " + peek(0)); 
        pop(0); 
        System.out.println("Peek 0: " + peek(0)); 
	}
	
	public static int pop(int stacknum) throws Exception{
		if(isEmpty(stacknum)){
			throw new Exception("Empty stack");
		}
		int data = array[absTopOfStack(stackpointer[stacknum])];
		stackpointer[stacknum]--;
		return data;
		
	}
	public static void push(int stacknum,int data) throws Exception{
		if(isFull(stacknum)){
			throw new Exception("full");
		}
		array[absTopOfStack(stacknum)+1]=data;
		stackpointer[stacknum]++;
	}
	static int peek(int stackNum) { 
        return array[absTopOfStack(stackNum)]; 
    } 
	public static boolean isEmpty(int stacknum){
		return stackpointer[stacknum]==-1;
	}
	public static boolean isFull(int stacknum){
		return stackpointer[stacknum]+1>=stacksize;
	}
	public static int absTopOfStack(int stacknum){
		return stacksize*stacknum+stackpointer[stacknum];
	}
}
